package com.example.iterator.v1;

public class LinkedList_<T> {

    Node head=null;
    Node tail=null;
    private int size=0;

    public void add(T t){
        Node node = new Node(t);
        node.next=null;

        if (head==null){
            head=node;
            tail=node;
        }
        tail.next=node;
        tail=node;
        size++;
    }

    private class Node{
        private T value;
        Node next;

        public Node(T t) {
            this.value = t;
        }
    }

    public int size() {
        return size;
    }

    public T get(int i){
        Node node=head;
        for (int j = 0; j < i; j++) {
            node=node.next;
        }
        return node.value;
    }
}
